#!/bin/bash
. scripts/search/export-keys
. scripts/search/assumptions

# delete spruce file
curl -s --insecure -X DELETE -u $SPRUCEKEY: https://localhost:8181/dvn/api/data-deposit/v1.1/swordv2/edit-media/file/$FIRST_SPRUCE_FILE >/dev/null
# delete spruce dataset
curl -s --insecure -X DELETE -u $SPRUCEKEY: https://localhost:8181/dvn/api/data-deposit/v1.1/swordv2/edit/study/$FIRST_SPRUCE_DOI >/dev/null
# delete finch dataset
curl -s -X DELETE "http://localhost:8080/api/datasets/$FIRST_FINCH_DATASET_ID?key=$FINCHKEY" >/dev/null

# delete all dataverses
curl -s -X DELETE "http://localhost:8080/api/dataverses/chestnutsparrows?key=$FINCHKEY" >/dev/null
curl -s -X DELETE "http://localhost:8080/api/dataverses/sparrows?key=$FINCHKEY" >/dev/null
curl -s -X DELETE "http://localhost:8080/api/dataverses/finches?key=$FINCHKEY" >/dev/null
curl -s -X DELETE "http://localhost:8080/api/dataverses/wrens?key=$FINCHKEY" >/dev/null
curl -s -X DELETE "http://localhost:8080/api/dataverses/birds?key=$FINCHKEY" >/dev/null
curl -s -X DELETE "http://localhost:8080/api/dataverses/spruce?key=$SPRUCEKEY" >/dev/null
curl -s -X DELETE "http://localhost:8080/api/dataverses/chestnuttrees?key=$SPRUCEKEY" >/dev/null
curl -s -X DELETE "http://localhost:8080/api/dataverses/trees?key=$SPRUCEKEY" >/dev/null

echo "Making sure finch can't see anything (silence is golden)"
diff <(curl -s "http://localhost:8080/api/search?q=*&key=$FINCHKEY" | jq '.data.total_count') scripts/search/tests/expected/zero
echo Done
echo "Making sure spruce can't see anything (silence is golden)"
diff <(curl -s "http://localhost:8080/api/search?q=*&key=$SPRUCEKEY" | jq '.data.total_count') scripts/search/tests/expected/zero
echo Done
